package iet.jxufe.cn.android.productanti_counterfeitingtraceabilitysystem.utils;

import android.util.Log;

import org.json.JSONObject;

import iet.jxufe.cn.android.productanti_counterfeitingtraceabilitysystem.entity.Product;
import iet.jxufe.cn.android.productanti_counterfeitingtraceabilitysystem.entity.Trace;
import iet.jxufe.cn.android.productanti_counterfeitingtraceabilitysystem.entity.User;

public class JSONObjectUtils {


    public JSONObjectUtils() {}

    // 1.有关登录

    // 处理登录按钮点击后获得的JSON
    public static User dealLogin(JSONObject info,User user)  {

        try{
            int userId = info.getInt("userId");
            int role = info.getInt("role");
            user.setUserId(userId);
            user.setRole(role);
            user.setEmail(info.getString("email"));
        }catch (Exception e){
            e.printStackTrace();
        }

        return user;
    }


    // 2.有关生产商


    // 3.有关经销商


    // 4.有关消费者
    public static String getMessage(JSONObject info)  {
        String res = new String();
        try{
            res = info.getString("message");
        }catch (Exception e){
            e.printStackTrace();
        }

        return res;
    }
    public static Product getProduct(JSONObject info)  {
        Product product = new Product();
        try{
            product = (Product) info.get("resultProduct");
        }catch (Exception e){
            e.printStackTrace();
        }

        return product;
    }

    public static Trace getTrace(JSONObject info)  {
        Trace trace = new Trace();
        try{
            trace = (Trace) info.get("resultTrace");
        }catch (Exception e){
            e.printStackTrace();
        }

        return trace;
    }

    // 5.其它

}